<?php
class Conference{
	static function start(){
		if(!User::checkAccess('admin'))die('Ошибка доступа');
		$d = $_POST;
		if(isset($d['form'])&&$d['form']){
			$res['title'] 	= "Начало конференции";
			$res['html'] 	= Template::parse('conference/start');
		}else if(isset($d['end_date'])){
			DB::exec_("insert into `conference` (`begin_date`,`end_date`) values (now(),'".$d['end_date']."')");
			$res['state'] 	= 1;
		}
		echo json_encode($res);
	}
	
	static function getEndDate(){
		$conf = DB::query("select end_date from conference");
		if(count($conf)==0){
			return -1;
		}else{
			return $conf[count($conf)-1]['end_date'];
		}
	}
	
	
	static function getState(){
		$conf = DB::query("select end_date from conference");
		if(count($conf)==0){
			return -1;
		}else{
			$end_date = new DateTime($conf[count($conf)-1]['end_date']);
			$difference = timestamp_($end_date->format('Y-m-d'))-timestamp_(date('Y-m-d'));
			if($difference<=0){
				return -1;
			}else{			
				return 1;
			}
		}
	}
}

?>